package com.parkwalk.xxx;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;

import com.parkwalk.xxx.ui.componentc.JCButton;
import com.parkwalk.xxx.ui.componentc.JCFrame;
import com.parkwalk.xxx.ui.componentc.JCLabel;
import com.parkwalk.xxx.ui.componentc.JCPasswordField;
import com.parkwalk.xxx.ui.componentc.JCTextField;

/**
 * @author borball
 * @date 2012-4-29
 * 
 */
public class LoginFrame extends JCFrame {
	private static final long serialVersionUID = -2553422006266016630L;
	
	private JCTextField textFieldName;
	private JCPasswordField textFieldPassword;
	
	public LoginFrame() {
		getContentPane().setLayout(null);
		
		JLabel labelName = new JCLabel("\u7528\u6237\u540D:");
		labelName.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		labelName.setBounds(93, 71, 54, 15);
		getContentPane().add(labelName);
		
		JLabel labelPassword = new JLabel("\u5BC6   \u7801:");
		labelPassword.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		labelPassword.setBounds(93, 113, 54, 15);
		getContentPane().add(labelPassword);
		
		textFieldName = new JCTextField();
		textFieldName.setBounds(164, 68, 161, 21);
		getContentPane().add(textFieldName);
		textFieldName.setColumns(10);
		
		textFieldPassword = new JCPasswordField();
		textFieldPassword.setBounds(164, 110, 161, 21);
		getContentPane().add(textFieldPassword);
		textFieldPassword.setColumns(10);
		
		JCButton buttonLogin = new JCButton("\u767B  \u5F55");
		buttonLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				login();
			}
		});
		
		buttonLogin.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		buttonLogin.setBounds(92, 174, 93, 23);
		getContentPane().add(buttonLogin);
		
		JCButton buttonCancel = new JCButton("\u53D6  \u6D88");
		buttonCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exit();
			}
		});
		
		buttonCancel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		buttonCancel.setBounds(232, 174, 93, 23);
		getContentPane().add(buttonCancel);
		getTitleContentPane().setLayout(null);
		
		JCLabel labelLogo = new JCLabel("  xxx\u7BA1\u7406\u7CFB\u7EDF 1.0");
		labelLogo.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		labelLogo.setBounds(0, 0, 167, 25);
		getTitleContentPane().add(labelLogo);
		
		setSize(400, 300);
		centerWindow();
		setResizable(false);
		setVisible(true);
		setDefaultCloseOperation(3);
	}

	protected void exit() {
		setVisible(false);
		System.exit(EXIT_ON_CLOSE);
		
	}

	protected void login() {
		String username = textFieldName.getText();
		String password = String.valueOf(textFieldPassword.getPassword());
		
		System.out.println("username:" + username);
		System.out.println("password:" + password);
		
		dispose();
		
		MainFrame mainFrame = new MainFrame();
		mainFrame.setVisible(true);
		mainFrame.setSize(800, 600);
		mainFrame.centerWindow();
	}

}
